package com.situ.study.day11;

import org.junit.Test;

public class StringDemo {
    @Test
    public void test1() {
        String str = "java AndroidA";
        System.out.println(str.length());//13
        char[] chars = str.toCharArray();
        char ch = str.charAt(5);//A
        System.out.println(ch);

        System.out.println(str.indexOf('A'));//5
        System.out.println(str.indexOf('X'));//-1
        System.out.println(str.indexOf('A', 6));//12
        System.out.println(str.indexOf("And"));//5

        System.out.println(str.lastIndexOf('A'));//12
    }

    @Test
    public void test2() {
        String str = "java AndroidA";
        System.out.println(str.contains("And"));//true
        System.out.println(str.startsWith("java"));//true
        System.out.println(str.startsWith("And", 5));
        System.out.println(str.endsWith("oidA"));//true
        System.out.println(str.isEmpty());//false
        System.out.println("".isEmpty());//true   "abc"
        System.out.println("abc".isEmpty());//false
    }

    @Test
    public void test3() {
        //String str = "java And";
        char[] array = {'j', 'a', 'v', 'a', ' ', 'A', 'n', 'd'};
        String str = new String(array);
        System.out.println(str);
        char[] chars = str.toCharArray();
        for (char ch : chars) {
            System.out.print(ch + " ");
        }
    }

    @Test
    public void test4() {
        String str = "java AndroidA";
        String newStr = str.replace('A', 'B');
        System.out.println(str);//java AndroidA
        System.out.println(newStr);//java BndroidB
    }

    @Test
    public void test5() {
        String str = "java Android Python Vue";
        String[] array = str.split(" ");
        for (String s : array) {
            System.out.println(s);
        }
    }

    @Test
    public void test6() {
        String str = "java AndroidA";
        System.out.println(str.substring(5));//AndroidA
        System.out.println(str.substring(5, 8));//And
    }

    @Test
    public void test7() {
        String str = "    java AndroidA   ";
        System.out.println(str);
        System.out.println(str.trim());
    }

    @Test
    public void test11() {
        String str1 = "java";
        String str2 = "android";
        String str3 = "php";
        String str4 = "python";
        String str5 = "vue";
        String str = str1 + str2 + str3 + str4 + str5;
        System.out.println(str);

        StringBuilder builder = new StringBuilder("java");
        builder.append("android");
        builder.append("php");
        builder.append("python");
        builder.append("vue");
        System.out.println(builder);

        StringBuffer buffer = new StringBuffer("java");
        buffer.append("android").append("php").append("python").append("vue");
        System.out.println(buffer);

        String s = "Java" + "PHP" + "Python" + "C";
    }
}
